home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
dgsay.exe
/
lha
/
DGSAY.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1989-06-30
|
39KB
|
1,072 lines
{
╔═════════════════════════════════════════════════════════════════════════╗
║ ║
║ TITLE : DGSAY.TPU, Version 8907.01 ║
║ PURPOSE : Write formatted text to screen. ║
║ AUTHOR : David Gerrold, CompuServe ID: 70307,544 ║
║ _____________________________________________________________________ ║
║ ║
║ Written in Turbo Pascal, Version 5.5, ║
║ with routines from Turbo Professional, Version 5.0. ║
║ ║
║ Turbo Pascal is a product of Borland International. ║
║ Turbo Professional is a product of TurboPower Software ║
║ _____________________________________________________________________ ║
║ ║
║ This is not public domain software. This is shareware. ║
║ This software is copyright 1989, by David Gerrold. ║
║ ║
║ The Brass Cannon Corporation ║
║ 9420 Reseda Blvd., #804 ║
║ Northridge, CA 91324-2932. ║
║ ║
║ If you find this code useful, a donation of $25 is requested -- ║
║ not to me, but to the AIDS Project Los Angeles. Donations may ║
║ be forwarded via the Brass Cannon address. Thank you. ║
║ ║
╚═════════════════════════════════════════════════════════════════════════╝
}
{ ========================================================================= }
{ Compiler Directives : }
{ ========================================================================= }
{$R-} {Range checking off}
{$B+} {Boolean complete evaluation on}
{$S+} {Stack checking on}
{$I+} {I/O checking on}
{$N+,E+} {Simulate numeric coprocessor}
{$M 65520,16384,655360} {Turbo 3 default stack and heap}
{$V-} {Variable range checking off}
{ ========================================================================= }
{ ========================================================================= }
UNIT DGsay;
{ ========================================================================= }
INTERFACE
{ ========================================================================= }
USES
Dos, { TP5.5 unit }
TpDos, { Turbo Professional unit }
TpCrt, { Turbo Professional unit }
TpString, { Turbo Professional unit }
DgInit, { Dg initialization }
DgStr; { Dg string object }
{ ========================================================================= }
TYPE
{
The SayKrnl-Object is the kernel ancestor for Say-Ob (see below);
None of the methods in SayKrnlOb are intended to be directly called
by the user; they are for the internal workings of Say-Ob and its
descendants.
The variables Indent, Width, JustifyFlag, and NormalAttr,
should be accessed only by the methods in SayOb. The variable
CurrentAttr is for the object's internal bookkeeping and should
not be tampered with at all.
The Send and SendKrnl methods are virtual, so that a child object can
be spawned for writing directly to the printer or to a disk file. The
next version of this unit will contain such descendant objects.
}
SayKrnlOb = Object (StrOb)
Indent : byte; { left indent }
Width : byte; { paragraph width }
JustifyFlag : boolean; { right justify or not? }
NormalAttr : byte; { normal attribute }
CurrentAttr : byte; { current attribute }
Constructor Init;
Function GetLineBreak (CheckStr : string) : byte;
Function Justify (Jstr : string) : string;
Function WordWrap (Limit : byte) : string;
Procedure SendKrnl (SendStr : string); virtual;
Procedure Send (SendStr : string); virtual;
Procedure SayKrnl (AddStr : string);
end;
{
The Say-Object is a replacement for the WriteLn procedure. Use Say
and SayLn instead of Write and WriteLn. The difference is that Say
will automatically reformat consecutive lines of text. You can set
a defined screen width and SayOb will format the text to that width.
You may also specify a left-indent).
Use consecutive Say ('<text>') commands to output formatted text
to the screen. Use a SayLn ('<text>') command to end the paragraph
and empty the SayOb buffer. Two consecutive SayLn ('') commands will
end the paragraph and output a blank line to the screen;
If there is no text in the SayOb buffer, you may use SayLn ('') to
produce a blank line on screen.
}
SayOb = Object (SayKrnlOb)
Constructor Init;
Procedure SetIndent (I : byte);
Procedure SetWidth (W : byte);
Procedure SetAttr (A : byte); { set NormalAttr }
Procedure SetParams (I, W, A : byte;
Jflag : boolean);
Procedure JustOn;
Procedure JustOff;
Function AttrStr (SetStr : string;
A : byte) : string;
Procedure SayLn (AddStr : string);
Procedure Say (AddStr : string);
Procedure SayPara (AddStr : string);
Procedure SayAttr (AddStr : string;
Attr : byte);
end;
VAR
Simon : SayOb;
CONST
TabStr = ' '; { standard para indent }
{ ========================================================================= }
PROCEDURE SayDoc; { simultaneous doc/demo }
{ ========================================================================= }
IMPLEMENTATION
{ ========================================================================= }
CONSTRUCTOR SayKrnlOb.Init;
BEGIN
S := '';
Indent := 5;
Width := 70;
JustifyFlag := true;
NormalAttr := TextAttr;
CurrentAttr := TextAttr;
END;
{ ========================================================================= }
FUNCTION SayKrnlOb.GetLineBreak (CheckStr : string) : byte;
{
Locates the place to break the string for Wordwrap, allowing for
imbedded control characters. Also used by the Justify function to
check the length of the string to be justified.
}
VAR
Len : byte absolute CheckStr;
Loop : byte;
Ctr : byte;
BEGIN
Ctr := Width; { break here }
Loop := 0;
Repeat
inc (Loop); { count through str }
if CheckStr [Loop] = #0 then begin { if attribute change }
inc (Ctr, 2); { count it }
inc (Loop); { step past it }
end;
Until
(Loop >= Ctr)
or
(Loop >= Len); { until end of str }
GetLineBreak := Ctr; { return count }
END;
{ ========================================================================= }
FUNCTION SayKrnlOb.Justify (Jstr : string) : string;
{
Returns a string internally padded with spaces so that length = limit.
}
VAR
Jlen : byte absolute Jstr;
Loop : byte;
LineB